package kara;

import java.io.*;

public class A108 {
    static int n;
    static int[] pre;
    static BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log=new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        String s = read.readLine();
        n=Integer.parseInt(s);
        pre=new int[n+1];
        for(int i=1;i<=n;i++){
            pre[i]=i;
        }
for(int i=1;i<=n;i++){
    String[] s1 = read.readLine().split(" ");
    int i1 = Integer.parseInt(s1[0]);
    int i2 = Integer.parseInt(s1[1]);
    if(isSameSet(i1,i2)){
        System.out.println(i1+" "+i2);
        return;
    }
    else join(i1,i2);
}

    }

  static  void join(int a,int b){
int aRoot=find(a);
int bRoot=find(b);
pre[aRoot]=bRoot;
    }
    static int find(int a){
        if(pre[a]!=a)pre[a]=find(pre[a]);
        return pre[a];
    }
    static boolean isSameSet(int a,int b){
        return find(a)==find(b);
    }
}
